﻿/* 
* Copyright (c) 2009, SCUT 06级计科2班软件工程第6小组
* All rights reserved. 
*
* 作    者：
* 完成日期：
*  
* 摘    要：系统管理，如系统功能模块启用管理，系统服务配置管理
*
* 备    注：
*
*/
using System;
using System.Collections.Generic;
using System.Web;


public static class SystemMan
{
	//返回上传secLevel级别档案需要的积分
	public static Int32 GetUploadPoint(ArchiveSecurityLevel secLevel)
	{
		SystemConfigure cfg = CacheMan.GetSystemConfigure();
		return cfg.UploadArchivePoint[(Int32)secLevel];
	}
	//返回下载secLevel级别档案需要的积分
	public static Int32 GetDownloadPoint(ArchiveSecurityLevel secLevel)
	{
		SystemConfigure cfg = CacheMan.GetSystemConfigure();
		return cfg.DownloadArchivePoint[(Int32)secLevel];
	}
	//判断系统功能是否已开启
	public static Boolean IsFunctionEnabled(FounctionType func)
	{
		SystemConfigure cfg = CacheMan.GetSystemConfigure();
		return (cfg.SystemFunction & func) != 0;
	}
	//返回上传不同档案所需积分，ugly code
	public static String UploadPoints()
	{
		SystemConfigure cfg = CacheMan.GetSystemConfigure();
		return cfg.UploadArchivePoint[0].ToString() + "," + cfg.UploadArchivePoint[1] + ","
			+ cfg.UploadArchivePoint[1] + "," + cfg.UploadArchivePoint[2];
	}


	//返回数据库系统信息
	public static SystemConfigure GetSystemConfigures()
	{
		return CacheMan.GetSystemConfigure();
	}

	//根据网页提交的数据更新数据库系统信息
	public static Boolean UpdateSystemConfigures(HttpRequest request, HttpResponse response)
	{
		FounctionType ft = 0;
		Int32[] upPoint;
		Int32[] dnPoint;
		try
		{
			ft = request.Form["login"] == "on" ? ft | FounctionType.Login : ft;
			ft = request.Form["register"] == "on" ? ft | FounctionType.Register : ft;
			ft = request.Form["upload"] == "on" ? ft | FounctionType.UploadArchive : ft;
			ft = request.Form["download"] == "on" ? ft | FounctionType.DownloadArchive : ft;
			ft = request.Form["leaveword"] == "on" ? ft | FounctionType.LeaveWord : ft;
			upPoint=new Int32[] {
					Convert.ToInt32(request.Form["ulPublicPoint"]),
					Convert.ToInt32(request.Form["ulSharePoint"]),
					Convert.ToInt32(request.Form["ulPrivatePoint"]),
					Convert.ToInt32(request.Form["ulSafePoint"]) };
			dnPoint=new Int32[] {
				Convert.ToInt32(request.Form["dlPublicPoint"]),
				Convert.ToInt32(request.Form["dlSharePoint"]),
				Convert.ToInt32(request.Form["dlPrivatePoint"]),
				Convert.ToInt32(request.Form["dlSafePoint"])};			
		}
		catch (System.Exception e)
		{
			return false;			
		}
		SystemConfigure cfg = GetSystemConfigures();
		cfg.SetSytstemFunction(ft);
		cfg.UpdateUploadPoint(upPoint);
		cfg.UpdateDownloadPoint(dnPoint);
		return DAMS.DataAccess.UpdateSystemConfigure(cfg);
	}
}
